<?php

namespace app\teacher\model;

use app\common\model\BaseModel;
use think\Model;
use app\common\model\TeacherMoneyLog as TeacherMoneyLogModel;

class TeacherMoneyLog extends TeacherMoneyLogModel
{


    public function courseOrder()
    {
        return $this->hasOne(CourseOrder::class, 'course_order_id', 'source_id');
    }



    /**
     * 账号明细
     */
    public static function getLog($teacherId, $size = 20)
    {
        $logs = self::with(['courseOrder' => function ($query) {
            $query->with('user');
        }])->where('teacher_id', $teacherId)->where('source', 1)->order('createtime desc')->paginate($size);
        foreach ($logs->items() as &$val) {
            $val['order_no'] = $val['course_order'] ? $val['course_order']['order_no'] : '';
            $val['nickname'] = $val['order_no'] ? $val['course_order']['user']['nickname'] : '';
            $val['avatar'] = $val['order_no'] ? $val['course_order']['user']['avatar'] : '';
            unset($val['course_order']);
        }
        return $logs;
    }


}
